#环境:centos6.5i386 i386
#安装包在:email0dot0@163.com@http://yunpan.360.cn\root\install_and_config\nginx\
#自动化安装nginx1.6.0
#文件编写风格:禁止大量使用cd, 禁止将&&写在行首。&&写在行首影响观赏性，&&写的行尾可能会忘记写，看自己选择。
#此脚本没有检测nginx的依赖项是否已经安装，只适合于刚刚安装好操作系统的情况下使用

#!/bin/sh
#PkRepo:package repository : 安装包存放目录
#DestHm:destination home : 目标安装目录
#LdCfHm:ld conf home : 

PkRepo=/usr/tmpx/install/nginx/pack_repo
UnpkHm=/usr/tmpx/install/nginx/unpack_home
LdCfHm="/etc/ld.so.conf.d/"
DestHm=/usr/local/

# init
test -d $PkRepo && \
rm -fr $UnpkHm && mkdir -p $UnpkHm && \
cd /tmp && \
export progress=begin && \
true

# install pcre
test $progress == begin && \
PackFull=pcre-8.35 PackSimple=pcre && \
export progress="begin_extract_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar jxf $PkRepo/$PackFull.tar.bz2 -C $UnpkHm && \
export progress="end_extract_$PackFull" && \
cd /tmp && true

# extract openssl
test $progress == "end_extract_$PackFull" && \
PackFull=openssl-1.0.1g PackSimple=not_used && \
export progress="begin_extract_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar zxf $PkRepo/$PackFull.tar.gz -C $UnpkHm && \
export progress="end_extract_$PackFull" && \
cd /tmp && true

# install libxml2
test $progress == "end_extract_$PackFull" && \
PackFull=libxml2-2.7.6 && PackSimple=libxml2 && \
export progress="begin_install_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar zxf $PkRepo/$PackFull.tar.gz -C $UnpkHm && cd $UnpkHm/$PackFull && \
./configure && make && make install && \
ldconfig && ldconfig -p | grep ${PackSimple} && \
export progress="end_install_$PackFull" && \
cd /tmp && true

# install libxslt
test $progress == "end_install_$PackFull" && \
PackFull=libxslt-1.1.24 && PackSimple=libxslt && \
export progress="begin_install_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar zxf $PkRepo/$PackFull.tar.gz -C $UnpkHm && cd $UnpkHm/$PackFull && \
./configure && make && make install && \
(! test -f $LdCfHm/local.conf) && echo "/usr/local/lib" >> $LdCfHm/local.conf && \
ldconfig && ldconfig -p | grep ${PackSimple} && \
export progress="end_install_$PackFull" && \
cd /tmp && true

# install zlib
test $progress == "end_install_$PackFull" && \
PackFull=zlib-1.2.8 && PackSimple=zlib && \
export progress="begin_install_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar zxf $PkRepo/$PackFull.tar.gz -C $UnpkHm && cd $UnpkHm/$PackFull && \
./configure && make && make install && \
ldconfig && ldconfig -p | grep z && \
export progress="end_install_$PackFull" && \
cd /tmp && true

# rename jpegsrc.v9.tar.gz to jpeg-9.tar.gz
# install jpegsrc.v9
test $progress == "end_install_$PackFull" && \
PackFull=jpeg-9 && PackSimple=jpeg && \
export progress="begin_install_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar zxf $PkRepo/$PackFull.tar.gz -C $UnpkHm && cd $UnpkHm/$PackFull && \
./configure && make && make install && \
ldconfig && ldconfig -p | grep ${PackSimple} && \
export progress="end_install_$PackFull" && \
cd /tmp && true

# install libpng
# check ./configure contains: png jpeg
test $progress == "end_install_$PackFull" && \
PackFull=libpng-1.6.11 && PackSimple=libpng && \
export progress="begin_install_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar zxf $PkRepo/$PackFull.tar.gz -C $UnpkHm && cd $UnpkHm/$PackFull && \
./configure && make && make install && \
ldconfig && ldconfig -p | grep ${PackSimple} && \
export progress="end_install_$PackFull" && \
cd /tmp && true

# install libgd
test $progress == "end_install_$PackFull" && \
PackFull=libgd-2.1.0 && PackSimple=libgd && \
export progress="begin_install_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar zxf $PkRepo/$PackFull.tar.gz -C $UnpkHm && cd $UnpkHm/$PackFull && \
./configure --with-png=/usr/local && make && make install && \
ldconfig && ldconfig -p | grep ${PackSimple} && \
export progress="end_install_$PackFull" && \
cd /tmp && true

# rename GeoIP.tar.gz to GeoIP-1.4.8.tar.gz
# install GeoIP
test $progress == "end_install_$PackFull" && \
PackFull=GeoIP-1.4.8 && PackSimple=GeoIP && \
export progress="begin_install_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar zxf $PkRepo/$PackFull.tar.gz -C $UnpkHm && cd $UnpkHm/$PackFull && \
CPPFLAGS=" -I/usr/local/zlib-1.2.8/include/ " LDFLAGS=" -L/usr/local/zlib-1.2.8/lib/ " ./configure && make && make install && \
ldconfig && ldconfig -p | grep ${PackSimple} && \
export progress="end_install_$PackFull" && \
cd /tmp && true

# install libunwind
test $progress == "end_install_$PackFull" && \
PackFull=libunwind-1.1 && PackSimple=libunwind && \
export progress="begin_install_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar zxf $PkRepo/$PackFull.tar.gz -C $UnpkHm && cd $UnpkHm/$PackFull && \
./configure --prefix=$DestHm/$PackFull && make && make install && \
echo "$DestHm/$PackFull/lib" > $LdCfHm/$PackSimple.conf && \
ldconfig && ldconfig -p | grep ${PackSimple} && \
export progress="end_install_$PackFull" && \
cd /tmp && true

# install gperftools
test $progress == "end_install_$PackFull" && \
PackFull=gperftools-2.1 && PackSimple=gperftools && \
export progress="begin_install_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar zxf $PkRepo/$PackFull.tar.gz -C $UnpkHm && cd $UnpkHm/$PackFull && \
./configure && make && make install && \
ldconfig && ldconfig -p | grep profiler && \
export progress="end_install_$PackFull" && \
cd /tmp && true

# install libatomic_ops
test $progress == "end_install_$PackFull" && \
PackFull=libatomic_ops-7.4.2 && PackSimple=libatomic_ops && \
export progress="begin_install_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar zxf $PkRepo/$PackFull.tar.gz -C $UnpkHm && cd $UnpkHm/$PackFull && \
./configure --enable-shared && make && make install && \
ldconfig && ldconfig -p | grep ${PackSimple} && \
export progress="end_install_$PackFull" && \
cd /tmp && true

# install nginx
test $progress == "end_install_$PackFull" && \
((userdel -r UserNginx ; groupdel  GroupNginx) || true) && \
groupadd GroupNginx && useradd UserNginx -G GroupNginx && \
PackFull=nginx-1.6.0 && PackSimple=nginx && \
export progress="begin_install_$PackFull" && \
rm -fr $UnpkHm/$PackFull && tar zxf $PkRepo/$PackFull.tar.gz  -C $UnpkHm && cd $UnpkHm/$PackFull && \
./configure\
 --prefix=/usr/local/nginx-1.6.0\
 --with-pcre=$UnpkHm/pcre-8.35\
 --with-openssl=$UnpkHm/openssl-1.0.1g\
 --user=UserNginx\
 --group=GroupNginx\
 --with-rtsig_module\
 --with-select_module\
 --with-poll_module\
 --with-file-aio\
 --with-http_ssl_module\
 --with-http_realip_module\
 --with-http_addition_module\
 --with-http_xslt_module\
 --with-http_image_filter_module\
 --with-http_geoip_module\
 --with-http_sub_module\
 --with-http_dav_module\
 --with-http_flv_module\
 --with-http_gzip_static_module\
 --with-http_random_index_module\
 --with-http_secure_link_module\
 --with-http_degradation_module\
 --with-http_stub_status_module\
 --with-mail\
 --with-mail_ssl_module\
 --with-google_perftools_module\
 --with-libatomic&&\
make && make install && \
export progress="end_install_$PackFull" && \
cd /tmp && true
